package com.dungeon.crawl;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

public class CombatView extends View{

	//Global vars
	//Vars holding various info about screen size
	int XscreenOffset, YscreenOffset;
	//array to keep track of all bitmaps
	Bitmap[] figure = new Bitmap[2];
	//int index values for all bitmaps
	int heroStand = 0;
	int bGStand = 1;
	//the data for the hero's image
	hero player;
	//dummy paint var
	private final Paint paint = new Paint();

	public CombatView(Context context) {
		super(context);
		loadImage(R.drawable.pbg_combat, bGStand, context, 80, 82);
		loadImage(R.drawable.knight_combat, heroStand, context, 92, 78);
		player = new hero(0);
	}

	public class hero {
		Bitmap currentImg;
		int stand = 0;
		public hero(int prof) {
			//setBitmaps(prof);
			currentImg = figure[stand];
		}
		public void setBitmaps(int prof) {
			switch (prof) {	
			case 0:
				
				break;
			}
		}
		public Bitmap getImg() {
			return currentImg;
		}
	}

	/**
	 * Initializes the different bitmaps on canvases for different types of figures needed.
	 * 
	 * @param tile
	 */
	public void loadImage(int drawable, int key, Context context, int width, int height) {
		//converts drawable to bitmap
		BitmapFactory.Options ops = new BitmapFactory.Options();
		ops.inJustDecodeBounds = true;
		//sets bitmap to a specific place in an array indicated by key
		Bitmap temp = BitmapFactory.decodeResource(context.getApplicationContext().getResources(), drawable);
		figure[key] = Bitmap.createScaledBitmap(temp, width, height, false);
	}

	//measures size of screen to position bitmaps for drawing
	protected void OnSizeChanged(int w, int h, int oldw, int oldh) {
		super.onSizeChanged(w, h, oldw, oldh);
		//establishes space on either side of each bitmap across & down
		XscreenOffset = (int) Math.floor(w / 4);
		YscreenOffset = (int) Math.floor((h - player.getImg().getHeight()) / 2);
	}
	
	//drawing time!
	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.drawBitmap(player.getImg(), 80, 40, paint);
		canvas.drawBitmap(figure[1], 360, 40, paint);
	}
}
